<%@page import="java.util.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>验证页</title>
</head>
<body>
<%!
// 变量
Map<String,String> map = new HashMap<String,String>();
boolean flag = false;
// 方法
boolean validate(String username,String password){
	String pwd = map.get(username);
	if(pwd!=null && pwd.equals(password)){
		return true;
	} else {
		return false;
	}
}
%>

<%
// 模拟库数据
map.put("fhzheng","123456");
map.put("xxzhou","123456");
map.put("peter","123456");
map.put("tom","333");
map.put("apache","999");
map.put("javaee","666");

// 获取提交的数据
String name = request.getParameter("username");
String pwd = request.getParameter("password");
if(name==null||name==""||pwd==null||pwd==""){	// 开关前置，没有数据，无法验证
	response.sendRedirect("login.jsp");
}
flag = validate(name, pwd);	// 验证
if(flag){
	// 置session，记录用户登录信息
	session.setAttribute("username", name);
	session.setAttribute("password", pwd);
	// 跳转导航业务到主界面
	response.sendRedirect("main.jsp");
} else {
%>
	<div style="text-align: center;">
		<span style="font-size: 26px;">用户登录失败</span>
	</div>
	<br>
	<div style="text-align: center;">
		<a href="login.jsp">重新登录系统</a>	
	</div>
<%
}
%>
</body>
</html>